package com.imooc.alllearning.util;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 公共元数据处理器
 * @Author: crowsjian
 * @Date: 2020/3/28 11:48
 */
@Component
@Slf4j
public class ComonMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("新建的时候，开始填充系统字段！");
        this.strictInsertFill(metaObject, "created", Date.class, new Date());
        this.strictInsertFill(metaObject, "modified", Date.class, new Date());
        this.strictInsertFill(metaObject, "creater", String.class, "TODO 从上下文获取当前人");
        this.strictInsertFill(metaObject, "operator", String.class, "TODO 从上下文获取当前人");
        this.strictInsertFill(metaObject, "status", Integer.class, 0);
        this.strictInsertFill(metaObject, "version", Long.class, 1L);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("更新的时候，开始填充系统字段！");
        this.strictUpdateFill(metaObject,"modified", Date.class, new Date());
        this.strictUpdateFill(metaObject,"operator", String.class, "TODO 从上下文获取当前人");
    }
}
